import {
  ViewController,
  IExpBarControlController,
  ViewEngineBase,
  IExpViewState,
  IExpViewEvent,
} from '@ibiz-template/runtime';
import {
  IAppDEDataViewExplorerView,
  IAppDEGridExplorerView,
  IAppDEListExplorerView,
} from '@ibiz/model-core';
/**
 * 导航视图引擎基类
 *
 * @author zk
 * @date 2023-05-30 06:05:44
 * @export
 * @class ExpViewEngine
 * @extends {ViewEngineBase}
 */
export class ExpViewEngine extends ViewEngineBase {
  protected declare view: ViewController<
    | IAppDEGridExplorerView
    | IAppDEDataViewExplorerView
    | IAppDEListExplorerView,
    IExpViewState,
    IExpViewEvent
  >;

  /**
   * 导航栏部件名称
   *
   * @author zk
   * @date 2023-05-30 06:05:34
   * @readonly
   * @type {string}
   * @memberof ExpViewEngine
   */
  get expBarName(): string {
    throw Error('子类实现');
  }

  /**
   * 表格导航栏部件控制器
   *
   * @author zk
   * @date 2023-05-29 04:05:32
   * @readonly
   * @memberof GridExpViewEngine
   */
  get expBar(): IExpBarControlController {
    return this.view.getController(this.expBarName) as IExpBarControlController;
  }

  /**
   * 组件创建
   *
   * @author zk
   * @date 2023-05-29 04:05:56
   * @memberof GridExpViewEngine
   */
  async onCreated(): Promise<void> {
    super.onCreated();
    const { childNames } = this.view;
    childNames.push(this.expBarName);
    if (!this.view.slotProps[this.expBarName]) {
      this.view.slotProps[this.expBarName] = {};
    }
    this.view.slotProps[this.expBarName].srfnav = this.view.state.srfnav;
  }

  /**
   *  组件挂载
   *
   * @author zk
   * @date 2023-05-29 04:05:42
   * @return {*}  {Promise<void>}
   * @memberof GridExpViewEngine
   */
  async onMounted(): Promise<void> {
    await super.onMounted();
    const { model } = this.view;
    // 默认加载
    if (!this.view.state.noLoadDefault && model.loadDefault) {
      this.expBar.load();
    }
  }
}
